class HomeController < ApplicationController
  before_filter :initialize_cart
  def index
    @page_title = "Indigenous Art Straight From the Source"
    #    @artists = Artist.find(:all, 
    #                           :conditions => ["published = ?", true], 
    #                           :limit => 10)
    
    if rand < 1 || read_fragment(:controller => "home", :action => 'index').nil?
      expire_fragment(:controller => "home", :action => 'index')
      if Artist.published_count > 0
        loop do
          offset = rand(Artist.published_count)
          
          @artist = Artist.find :first, :offset => offset, :conditions => ["published = ?", true]
          if !Picture.find_by_artist_id(@artist.id).nil?
            break
          end
        end
      end
      
      
      @newArt = Artwork.find(:all, :conditions => ["published = ?", true], :order => "id DESC", :limit => 4)
      
      # Max: This is not the correct way to get random data...
      @randArt = Artwork.find(:all, :conditions => ["published = ?", true])
      @randArt = @randArt.sort_by{rand}
      @randArt = @randArt[0,4]
    end
    #@randArt = Artwork.find(:all, :order => "RAND()", :limit => 4)
  end
  
  def flick_artist
    puts params[:artist_id]
    while 1
      offset = rand Artist.published_count
      @artist = Artist.find :first, :offset => offset, :conditions => ["published = ?", true]
      if params[:artist_id] != @artist.id.to_s and !Picture.find_by_artist_id(@artist.id).nil?
        break
      end
    end 
    render :partial => 'home/artist_flicker', :object => @artist
  end
  
  def learn_more
    
  end
  
  def about_us
    # Max
    @we_are = :awesome
  end
  
  def mission
    
  end
  
  def terms
    
  end
end
